/* 地图信息 */
var defaultPointIcon = "/wcsi/img/defaultShop.png";
var arcGisUrl = "http://39.107.125.44:6080";
var map;
var toolbar;
var partLayer;
var centerX = 106.638;
var centerY = 26.684;
var shopPoint;
var drawHandler;
var oldPoint;
require([ "esri/map", "esri/Color", "esri/graphic", "esri/InfoTemplate",
		"esri/SpatialReference", "esri/renderers/HeatmapRenderer",
		// 控件
		"esri/dijit/OverviewMap", "esri/dijit/Scalebar",
		"esri/dijit/Measurement", "esri/units",
		// 图层
		"tdlib/TDTLayer", "tdlib/TDTAnnoLayer", "tdlib/TDT_ImgLayer",
		"tdlib/TDT_ImgAnnoLayer", "esri/layers/GraphicsLayer",
		"esri/layers/ArcGISDynamicMapServiceLayer",
		"esri/layers/ArcGISTiledMapServiceLayer", "esri/layers/FeatureLayer",
		// 图形要素
		"esri/geometry/Point", "esri/geometry/Polyline",
		"esri/geometry/Polygon", "esri/geometry/Circle",
		// 样式
		"esri/symbols/TextSymbol", "esri/symbols/SimpleMarkerSymbol",
		"esri/symbols/PictureMarkerSymbol", "esri/symbols/SimpleLineSymbol",
		"esri/symbols/SimpleFillSymbol",
		// 标签
		"esri/symbols/Font", "esri/layers/LabelClass",
		// 查询
		"esri/tasks/query", "esri/tasks/QueryTask", "esri/toolbars/draw",
		"esri/dijit/Popup", "esri/dijit/PopupTemplate", "dojo/dom",
		"dojo/dom-construct" ], function(Map, Color, Graphic, InfoTemplate,
		SpatialReference, HeatmapRenderer, OverviewMap, Scalebar, Measurement,
		Units, TDTLayer, TDTAnnoLayer, TDT_ImgLayer, TDT_ImgAnnoLayer,
		GraphicsLayer, ArcGISDynamicMapServiceLayer,
		ArcGISTiledMapServiceLayer, FeatureLayer, Point, Polyline, Polygon,
		Circle, TextSymbol, SimpleMarkerSymbol, PictureMarkerSymbol,
		SimpleLineSymbol, SimpleFillSymbol, Font, LabelClass, Query, QueryTask,
		Draw, Popup, PopupTemplate, dom, domConstruct) {

	map = new Map("map", {
		slider : false,
		logo : false,
		showLabels : true,
		center : [ centerX, centerY ],
		zoom : 14,
		minZoom : 17,
	});

	// 初始化比例尺
	var scalebar = new Scalebar({
		map : map,
		attachTo : "bottom-left",
		scalebarUnit : "dual",
	});

	// 显示比例尺
	scalebar.show();
	drawHandler = Draw;
	var vec = new TDTLayer();// 切片线画图
	var veca = new TDTAnnoLayer();// 切片标注
	var img = new TDT_ImgLayer();
	var imga = new TDT_ImgAnnoLayer();
	map.addLayer(vec);
	map.addLayer(veca);

	map.graphics.on("mouse-down", function(evt) {
		console.log("graphicslayer:mouse-down");
		if (evt.graphic) {
			shopPoint = evt.graphic;
		}
		if (shopPoint) {
			oldPoint = evt.mapPoint;
			shopPoint.isMouseDown = true;
			map.disableMapNavigation();
			map.disablePan();
		}
	});
	map.on("mouse-drag", function(evt) {
		console.log("map:mouse-drag");
		if (shopPoint) {
			if (shopPoint.isMouseDown) {
				shopPoint.setGeometry(evt.mapPoint);
			}
		}
	});
	
	map.on("mouse-up", function(evt) {
		console.log("map:mouse-up");
		if (shopPoint) {
			oldPoint = null;
			map.enableMapNavigation();
			map.enablePan();
			shopPoint.isMouseDown = false;
		}
	});
	
//	//鼠标经过
//	map.graphics.on("mouse-over", function(evt) {
//		console.log("graphicslayer:mouse-over");
//		setPolygonMouseInSymbol(evt.graphic);
//		//evt.graphic.setSymbol(symbol);
//	});
//
//	//鼠标移开
//	map.graphics.on("mouse-out", function(evt) {
//		console.log("graphicslayer:mouse-out");
//		setPolygonMouseOutSymbol(evt.graphic);
//		//evt.graphic.setSymbol(symbol);
//	});
	
});

//创建坐标点
function createPoint(data){
	var symbol = new esri.symbol.PictureMarkerSymbol(defaultPointIcon,20,20).setOffset(0,10);
	var longitude =  data.longitude == '0' ? centerX : data.longitude;
	var latitude = data.latitude == '0' ? centerY : data.latitude;
	var myPoint = {
        "geometry": {
        	"type":"point",
            "x": longitude,
            "y": latitude,
            "spatialReference": { "wkid": 4326 }
        },
        "attributes": data,
        "symbol": symbol,
        "showType":"shop"
    };
	
	var graphic = getcurrentGraphic("shop");
	
	if (graphic == null) {
		graphic = new esri.Graphic(myPoint);
		graphic.symbol = symbol;
		graphic.showType = "shop";
	} else {
		var geometry = graphic.geometry;
		geometry.x = longitude;
		geometry.y = latitude;
		graphic.showType = "shop";
		graphic.setGeometry(geometry);
		graphic.setSymbol(symbol);
	}
	map.graphics.add(graphic);
	setTimeout(function() {
		map.centerAndZoom(graphic.geometry,map.getLevel());
//		map.centerAt(graphic.geometry);
	},500);
	
	shopPoint = graphic;
	return graphic;
}

function getcurrentGraphic(type) {
	var graphics;
	graphics = map.graphics.graphics;
	for (var i = 0; i < graphics.length; i++) {
		if (graphics[i]) {
			if (graphics[i].showType && graphics[i].showType == type) {
				return graphics[i];
			}
		}
	}
	return null;
};

(function () {
	var d={};
	var codeIconWidth=50;
	 var codeIconHeight=50;
	$("#avatar").error(function() { 
    	$(this).attr("src", "../img/empty.png"); 
    	$(this).error=null;
    	}); 
	/*jQuery("#avatar").bind("click",function(){
		PictureUploadBusiness();
	});*/
	/*$("#file").change(function () {
	    var $file = $(this);
	    var fileObj = $file[0];
	    var windowURL = window.URL || window.webkitURL;
	    var dataURL;
	    var $img = $("#avatar");

	    if (fileObj && fileObj.files && fileObj.files[0]) {
	        dataURL = windowURL.createObjectURL(fileObj.files[0]);
	        $img.attr('src', dataURL);
	    } else {
	        dataURL = $file.val();
	        var imgObj = document.getElementById("preview");
	        // 两个坑:
	        // 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
	        // 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
	        imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
	        imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

	    }
	});*/
	$("body").on("change", "#file", function (){
		 var $file = $(this);
		    var fileObj = $file[0];
		    var windowURL = window.URL || window.webkitURL;
		    var dataURL;
		    var $img = $("#avatar");

		    if (fileObj && fileObj.files && fileObj.files[0]) {
		        dataURL = windowURL.createObjectURL(fileObj.files[0]);
		        $img.attr('src', dataURL);
		    } else {
		        dataURL = $file.val();
		        var imgObj = document.getElementById("preview");
		        // 两个坑:
		        // 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
		        // 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
		        imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
		        imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

		    }
		});
	jQuery('#fileclick').on('click', function () {
		return  $("#file").click();
	});
	
	$("body").on("change", "#picfile", function (){
		var $file = $(this);
		var fileObj = $file[0];
		var windowURL = window.URL || window.webkitURL;
		var dataURL;
		var $img = $("#picIMG");
		
		if (fileObj && fileObj.files && fileObj.files[0]) {
			dataURL = windowURL.createObjectURL(fileObj.files[0]);
			
			var img =new Image();
			img.src=dataURL;
			img.onload = function() {
				var _imgWidth_act = img.naturalWidth;     //图片宽度
		        var _imgHeight_act = img.naturalHeight;   //图片高度
		        
		        var _imgWidth = img.naturalWidth;     //图片宽度
		        var _imgHeight = img.naturalHeight;   //图片高度
		        
		        if(_imgWidth_act>400){
		        	_imgWidth=400;
		        	_imgHeight =(400*_imgHeight_act)/_imgWidth_act;
		        }
		      
				 //var canvas=document.getElementById("picCanvals");
		        var canvas= document.createElement('canvas');
		        canvas.width=_imgWidth;  
                canvas.height=_imgHeight;
				 var ctx=canvas.getContext('2d');
				 ctx.drawImage(img,0, 0, _imgWidth,_imgHeight);
				$img.attr('src', canvas.toDataURL('dimg/png'));
				var file = document.getElementById('picfile');
				file.value = '';
			}
			//$img.attr('src', dataURL);
		} /*else {
			dataURL = $file.val();
			var imgObj = document.getElementById("preview");
			// 两个坑:
			// 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
			// 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
			imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
			imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
		}*/
	});
	jQuery('#picIMG').on('click', function () {
		return  $("#picfile").click();
	});
	/**
	 * 图片上传
	*/
	PictureUploadBusiness = function()
	{
	     var root=window.rootPath;	   
	     WebFilesUploader(
		           {
			        _webuploader:{
			            server: root + '/a/'+d.id+'/avatar',
			        	chunked:false
			        }
			    },
			    function(jsons)
			    {
			    	var avatarUrl=window.rootPath+'/a/'+'avatar/'+d.id;
			    	jQuery("#avatar").prop("src","#");
					jQuery("#avatar").prop("src",avatarUrl+'?t='+Math.random());
			    });
	};
	$(document).ready(function() {
		/*$("#buInfoEdit").attr("href",$("#goHome").attr("href")+"&&identify="+$('#identify').val());*/
		$("#userAccount").html($("#userName").val());
		showWxCode();
		showQRCode();
	});
	function showWxCode(){
		var registerOpenid =$("#registerOpenid").val();
		if(registerOpenid==undefined||registerOpenid=="")
			{
			$("#wxInfoEdit").html("立即绑定"); 
			$("#wxInfo").html("你还未绑定微信，绑定微信后可以直接通过微信扫码登录"); 
			}else
				{
				$("#wxInfoEdit").html("取消绑定"); 
				$("#wxInfo").html("你已经绑定微信，可以直接通过微信扫码登录"); 
				}
	}
    ///编辑商户信息
	$("#buInfoEdit").on('click', function () {
		jQuery('#checkModal').modal('show');
		getData();
	});
	 ///修改密码
	$("#pwdInfoEdit").on('click', function () {
		jQuery('#pwdModal').modal('show');
	});
	///头像上传
	$("#uploadPic").on('click', function () {
		jQuery('#picModal').modal('show');
	});
	
	//显示二维码
	function showQRCode(){
		var codeUrl =window.rootPath+$("#codeAdress").val();
		codeUrl=window.location.origin+codeUrl;
		$('#qrcode').html("");
		/*jQuery('#qrcode').qrcode(codeUrl);*/
		
		var qrcode =jQuery('#qrcode').qrcode({
		    render: "canvas", //也可以替换为table
		    width: 300,
		    height: 300,
		    text:codeUrl
		}).hide();
		var canvas=qrcode.find('canvas').get(0);

		var ctx=canvas.getContext('2d');
		var myImage=document.getElementById("qrCodeIco");
		ctx.drawImage(myImage, canvas.width/2-codeIconWidth/2, canvas.height/2-codeIconHeight/2, codeIconWidth, codeIconHeight);
		ctx.moveTo(canvas.width/2-codeIconWidth/2,canvas.height/2-codeIconHeight/2);//第一个起点
		ctx.lineTo(canvas.width/2+codeIconWidth/2,canvas.height/2-codeIconHeight/2);//第二个点
		ctx.lineTo(canvas.width/2+codeIconWidth/2,canvas.height/2+codeIconHeight/2);//第三个点（以第二个点为起点）
		ctx.lineTo(canvas.width/2-codeIconWidth/2,canvas.height/2+codeIconHeight/2);//第四个点（以第二个点为起点
		ctx.lineTo(canvas.width/2-codeIconWidth/2,canvas.height/2-codeIconHeight/2);//第五个点（以第二个点为起点）
		ctx.lineWidth = 5;
		ctx.strokeStyle = '#ffffff';
		ctx.stroke();
		$('#dimg').attr('src',canvas.toDataURL('dimg/png'));
		
	}
	 ///设置微信绑定
	$("#wxInfoEdit").on('click', function () {
		var code ="";
		var str ="请拿出手机，扫描屏幕右侧二维码立即进行绑定！";
		if($("#wxInfoEdit").html()=="立即绑定"){
			$.springLemonDialog({
				content : str,// 确认文本
				clickButton : function(sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
					if(index==0)
					{
						var codeUrl =window.rootPath+$("#codeAdress").val();
						 codeUrl=window.location.origin+codeUrl;
						 
						 $('#qrcode').html("");
						/*jQuery('#qrcode').qrcode(codeUrl);*/
						
						var qrcode =jQuery('#qrcode').qrcode({
						    render: "canvas", //也可以替换为table
						    width: 300,
						    height: 300,
						    text:codeUrl
						}).hide();
					 var canvas=qrcode.find('canvas').get(0);
					
					 var ctx=canvas.getContext('2d');
					 var myImage=document.getElementById("qrCodeIco");
					 ctx.drawImage(myImage, canvas.width/2-codeIconWidth/2, canvas.height/2-codeIconHeight/2, codeIconWidth, codeIconHeight);
					 ctx.moveTo(canvas.width/2-codeIconWidth/2,canvas.height/2-codeIconHeight/2);//第一个起点
		              ctx.lineTo(canvas.width/2+codeIconWidth/2,canvas.height/2-codeIconHeight/2);//第二个点
		              ctx.lineTo(canvas.width/2+codeIconWidth/2,canvas.height/2+codeIconHeight/2);//第三个点（以第二个点为起点）
		              ctx.lineTo(canvas.width/2-codeIconWidth/2,canvas.height/2+codeIconHeight/2);//第四个点（以第二个点为起点）
		              ctx.lineTo(canvas.width/2-codeIconWidth/2,canvas.height/2-codeIconHeight/2);//第五个点（以第二个点为起点）
		              ctx.lineWidth = 5;
		              ctx.strokeStyle = '#ffffff';
		              ctx.stroke();
		              
					 $('#dimg').attr('src',canvas.toDataURL('dimg/png'));
					}
					else{
						
					}
				}
			});
		}
		else
		{
			code="";
			str='确认取消微信绑定？';
		
			$.springLemonDialog({
				content : str,// 确认文本
				clickButton : function(sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
					if(index==0)
					{
						d2={
							"wxCode":code	
						}
						var url =window.rootPath
						+ '/ui/userset/setWxCode';
						jQuery.ajax({
			               	type : "post",
			               	url: encodeURI(url),            	
			               	dataType : 'json', 
			               	data: JSON.stringify(d2),
			               	contentType: 'application/json;charset=utf-8',
			               	success : function(data) {
			               		if (data.code == -1) {
									message("操作失败")
								} else {
									$("#registerOpenid").val("");
									showWxCode();
								}
			               	}
			        	});
					}
					else{
						
					}
				}
			});
		}
		
		
	});
	
	//重新设置密码
	jQuery('.savepwdBtn').on('click', function () {
    	
	    var url = window.rootPath +'/ui/userset/updatePwd';
	    
	    	d1={
	    			"opwd":sha256_digest($("#opwd").val()),
	    			"npwd":sha256_digest($("#npwd").val())
	    	}
	    	
	    	jQuery.ajax({
	            type: 'post',
	            url: encodeURI(url),
	            data: JSON.stringify(d1),
	            dataType: 'json',
	            contentType: 'application/json;charset=utf-8',
	            success: function (data) {
	            	if(data.code==-1){
	            		message(data.message);
	            	}
	            	else{
	            		
	            	}
	            	$("#opwd").val("");
	            	$("#npwd").val("");
	            	jQuery('#pwdModal').modal('hide');
	            }
	        });
        
});
	
    jQuery('.saveBtn').on('click', function () {
    	
		    var url = window.rootPath +'/ui/bussinessEdit/saveDetailWithFile';
		    
		    	d.shopName=$("#shopName").val();
		    	d.shopAdress=$("#shopAdress").val();
		    	d.areaMeasure=$("#areaMeasure").val();
		    	d.signPerson=$("#signPerson").val();
		    	d.cleaningPerson=$("#cleaningPerson").val();
		    	d.managementRange=$("#managementRange").val();
		    	
//		    	
//		    	if(d.areaInfo!=undefined){
//		    		d.areaInfo.id=$('#area').val();
//		    	} else{
//		    		d.areaInfo={"id":$('#area').val()};	
//		    	}
		    	
		    	if(d.arreaManagementPerson!=undefined){
		    		d.arreaManagementPerson.id=$('#areaMperson').val();
		    	}else{
		    		d.arreaManagementPerson={"id":$('#areaMperson').val()};
		    	}
		    	
		    	var data={
		    			"id":d.id,
		    			"shopName":d.shopName,
		    			"shopAdress":d.shopAdress,
		    			"areaMeasure":d.areaMeasure,
		    			"signPerson":d.signPerson,
		    			"cleaningPerson":d.cleaningPerson,
		    			"infoState":d.infoState.id,
		    			"longitude":shopPoint.geometry.x,
		    			"latitude":shopPoint.geometry.y,
		    			"managementRange":d.managementRange,
		    			//"areaInfo":d.areaInfo.id,//JSON.stringify({"id":d.areaInfo.id}),
		    			"level":$("#bussinessLevel").val(),
		    			"arreaManagementPerson":d.arreaManagementPerson.id,//JSON.stringify({"id":d.arreaManagementPerson.id}),
		    		    "businesssellerBaseInfo":d.businesssellerBaseInfo.id//JSON.stringify({"id":d.businesssellerBaseInfo.id})
		    	}
		    	
		    	/*d.areaInfo.id=$('#area').val();
		    	d.arreaManagementPerson.id=$('#areaMperson').val();*/
		    	
		    	/*jQuery.ajax({
		            type: 'post',
		            url: encodeURI(url),
		            data: JSON.stringify(d),
		            dataType: 'json',
		            contentType: 'application/json;charset=utf-8',
		            success: function (data) {
		            	if(data.code==-1){
		            		message(data.message);
		            	}
		            	else{
		            		
		            		$("#popupView").popup();
		            		$("#popupView").popup('open');
		            		$("#test").trigger("click"); 
		            	}
		            	jQuery('#checkModal').modal('hide');
		            	getData();
		            }
		        });*/
		    	
		    	$.ajaxFileUpload({
		    		url : url,
		    		secureuri : false,// 是否需要安全协议
		    		fileElementId : ["file"],// 文件上传的Id属性
		    		dataType : 'text',
		    		data : data,
		    		success : function(result, status) {
		    			if (status=="success") {
		    			}else{
		    				message(data.message);
		    			}
		    			jQuery('#checkModal').modal('hide');
		            	getData();
		    			
		    		}
		    	});
	        
    });
    
    //头像上传
    jQuery('.savepicBtn').on('click', function () {
    		var userId = $("#userId").val();
    		var url = window.rootPath +'/ui/userset/saveUserPic/'+userId;
    		var img =$("#picIMG");
	    	var imgs=img.attr("src");
	    	var data={
	    			"imgs":imgs
	    	}
	    	$.ajaxFileUpload({
	    		url : url,
	    		secureuri : false,// 是否需要安全协议
	    		fileElementId : ["picfile"],// 文件上传的Id属性
	    		dataType : 'text',
	    		data : data,
	    		success : function(result) {
    				getUserPic();
	    			jQuery('#picModal').modal('hide');
	    			
	    		}
	    	});
    	
    });
    
    //提交
    jQuery('.submitBtn').on('click', function () {
	    var url = window.rootPath +'/ui/bussinessEdit/submitDetailWithFile';

	    	d.shopName=$("#shopName").val();
	    	d.shopAdress=$("#shopAdress").val();
	    	d.areaMeasure=$("#areaMeasure").val();
	    	d.signPerson=$("#signPerson").val();
	    	d.cleaningPerson=$("#cleaningPerson").val();
	    	d.managementRange=$("#managementRange").val();
	    	
//	    	if(d.areaInfo!=undefined){
//	    		d.areaInfo.id=$('#area').val();
//	    	} else{
//	    		d.areaInfo={"id":$('#area').val()};	
//	    	}
	    	
	    	if(d.arreaManagementPerson!=undefined){
	    		d.arreaManagementPerson.id=$('#areaMperson').val();
	    	}else{
	    		d.arreaManagementPerson={"id":$('#areaMperson').val()};
	    	}
	    	
	    	/*d.areaInfo.id=$('#area').val();
	    	d.arreaManagementPerson.id=$('#areaMperson').val();*/
	    	var data={
	    			"id":d.id,
	    			"shopName":d.shopName,
	    			"shopAdress":d.shopAdress,
	    			"areaMeasure":d.areaMeasure,
	    			"signPerson":d.signPerson,
	    			"cleaningPerson":d.cleaningPerson,
	    			"infoState":d.infoState.id,
	    			"longitude":shopPoint.geometry.x,
	    			"latitude":shopPoint.geometry.y,
	    			"managementRange":d.managementRange,
	    			//"areaInfo":d.areaInfo.id,//JSON.stringify({"id":d.areaInfo.id}),
	    			"level":$("#bussinessLevel").val(),
	    			"arreaManagementPerson":d.arreaManagementPerson.id,//JSON.stringify({"id":d.arreaManagementPerson.id}),
	    		    "businesssellerBaseInfo":d.businesssellerBaseInfo.id//JSON.stringify({"id":d.businesssellerBaseInfo.id})
	    	}
	    	
	    	/*jQuery.ajax({
	            type: 'post',
	            url: encodeURI(url),
	            data: JSON.stringify(d),
	            dataType: 'json',
	            contentType: 'application/json;charset=utf-8',
	            success: function (data) {
	            	if(data.code==-1){
	            		message(data.message);
	            	}
	            	jQuery('#checkModal').modal('hide');
	            	getData();
	            }
	    	
	        });*/
	    	$.ajaxFileUpload({
	    		url : url,
	    		secureuri : false,// 是否需要安全协议
	    		fileElementId : ["file"],// 文件上传的Id属性
	    		dataType : 'text',
	    		data : data,
	    		success : function(result, status) {
	    			if (status=="success") {
	    				jQuery('#checkModal').modal('hide');
	    				getData();
	    			}
	    			else{
	    				message(data.message);
	    			}
	    		}
	    	});
});
    function getData(){
    		var identify =$("#identify").val();
        var url = window.rootPath +'/ui/bussinessEdit/getEditDetail/'+identify;
        jQuery.ajax({
            url:url,
            cache:false,
            type :"get",
            data:"",
            dataType:"json",
            contentType:'application/json;charset=utf-8',//解决返回数据中的中文乱码问题
            success:function(data){
            	d=data;
            	jQuery('#infoState').prop('readonly', 'readonly');
            	jQuery('#managementPerson').prop('readonly', 'readonly');
            	
            	if(data.infoState.title=="待认证")
            	{
            		jQuery('#cleaningPerson').prop('readonly', 'readonly');
            		jQuery('#managementRange').prop('readonly', 'readonly');
            		jQuery('#signPerson').prop('readonly', 'readonly');
            		jQuery('#shopAdress').prop('readonly', 'readonly');
            		jQuery('#pictureAdress').prop('readonly', 'readonly');
            		//$('#area').attr('disabled','disabled');
            		$('#bussinessLevel').attr('disabled','disabled');
            		$('#areaMperson').attr('disabled','disabled');
            		jQuery(".submitBtn").attr("disabled", true);
            		}
            	
            	/*var avatarUrl=window.rootPath+'/a/'+'avatar/'+data.pictureAdress;
        		jQuery("#avatar").prop("src",avatarUrl+'?t='+Math.random());
        		*/
        		var purl=data.pictureAdress;
				if(purl==undefined||purl==""){
					purl="../img/nopicture.png";
				}else{
					purl=window.rootPath+'/'+purl;
				}
				$("#avatar").attr("src",purl);
				
            	$("#shopName").val(data.shopName?data.shopName:'');
            	
            	var path ="";
        		if (data.infoState.title == '待认证') {
        			path="../img/authentication_in.png";
				} else if (data.infoState.title == '认证拒绝') {
					path="../img/authentication_notaccess.png";
				} else if (data.infoState.title == '认证通过') {
					path="../img/authentication_access.png";
				} else if (data.infoState.title == '初始化') {
					path="../img/authentication_init.png";
				} else if(data.infoState.title	==null){
					path ="";
				}
        		$("#infoState").attr('src',path);
            	/*$("#infoState").val(data.infoState.title);*/
            	
            	$("#shopAdress").val(data.shopAdress?data.shopAdress:'');
            	$("#areaMeasure").val(data.areaMeasure?data.areaMeasure:'');
            	$("#signPerson").val(data.signPerson?data.signPerson:'');
            	$("#cleaningPerson").val(data.cleaningPerson?data.cleaningPerson:'');
            	$("#managementRange").val(data.managementRange?data.managementRange:'');
            	$("#managementPerson").val(data.managementPerson.name);
            	if(data.businesssellerBaseInfo.bussinessLevel != undefined){
            		jQuery('#bussinessLevel').val(data.businesssellerBaseInfo.bussinessLevel.id);
            	}
//            	if(data.areaInfo!=undefined){
//            	jQuery('#area').val(data.areaInfo.id);
//            	}
            	
            	if(data.arreaManagementPerson!=undefined){
            		jQuery('#areaMperson').val(data.arreaManagementPerson.id);
            	}
            	//$('#area').val(data.areaInfo.id).selectmenu('refresh', true); 
            	//$('#areaMperson').val(data.arreaManagementPerson.id).selectmenu('refresh', true); 
            	//$("#area").find("option:contains('"+data.areaInfo.title+"')").attr("selected",true);
            	//jQuery('#area').val(data.areaInfo.id);
            	//$("#areaMperson").find("option:contains('"+data.arreaManagementPerson.name+"')").attr("selected",true);
            	//jQuery('#areaMperson').val(data.arreaManagementPerson.id);
            	
            	/*$("#managementPerson").html("管理人员: "+data.managementPerson.name); */
            	
            	createPoint(data);
            }
        })
    };
    //获取用户头像
    function getUserPic(){
    		var userId = $("#userId").val();
	    	var url = window.rootPath +'/ui/userset/getUserPic/'+userId;
	    	jQuery.ajax({
	    		url:url,
	    		cache:false,
	    		type :"get",
	    		data :"",
	    		dataType:"json",
	    		contentType:'application/json;charset=utf-8',//解决返回数据中的中文乱码问题
	    		success:function(data){
	    			var purl=data.user.pictureAddress;
	    			var pic = '';
	    			if(purl==undefined||purl==""){
	    				purl="../img/nopicture.png";
	    				pic = '../img/upload.png'; 
	    			}else{
	    				purl=window.rootPath+'/'+purl;
	    				pic = purl;
	    			}
	    			$("#userPic").prop("src",purl);
	    			$("#picIMG").prop("src",pic);
	    			reSizePic();
	    		}
	    	})
    };
    jQuery(document).ready(function () {
    		getUserPic();
    });
    
    $(window).resize(function() {
    		reSizePic();
    })
    
    function reSizePic(){
    		var UserPic = jQuery("#userPic");
		var divWidth = UserPic.width();
		divWidth = divWidth * 0.8;
		UserPic.height(divWidth);
    }
})();